# encoding: utf-8
# author: 侯佳涛
# file_name: tasks
# create_time: 2022/2/10, 下午3:10
from celery_tasks.sms.yuntongxun.sms_verify import CCP
from . import constants
from celery_tasks.main import celery_app


@celery_app.task(bind=True, name='send_sms_code', retry_backoff=3)  # 可以不指定名字，但是celery默认生成的任务名字会很长
def send_sms_code(self, mobile, sms_code):
    """
    发送短信异步任务
    :param self: 装饰器对象
    :param mobile: 手机号
    :param sms_code: 短信验证码
    :return: 0：成功 -1：失败
    """
    try:
        status = CCP().send_sms(constants.SEND_SMS_TEMPLATE_ID, mobile, (sms_code, constants.SMS_CODE_REDIS_EXPIRES // 60))

        return status
    except Exception as e:
        raise self.retry(exc=e, max_retries=3)

